/**
 * 
 */
package com.ofek.eventos.net.lks;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author Ofek
 *
 */
public class LKWhoKnowsWhatLog<ID> {
	public ID id;
	public HashSet<String> whoKnowsAboutIt = new HashSet<String>();
	public long highestVersion = -1;
	public HashMap<String,Long> whoKnowsWhatVersion = new HashMap<String, Long>();
	/**
	 * 
	 */
	public LKWhoKnowsWhatLog(final ID id) {
		this.id = id;
	}
	/**
	 * Removal is allowed if and only if
	 *  whoever knows about the existance of the item this log logs, is also knows about its highest version
	 * @return 
	 * 
	 * 
	 * 
	 */
	public boolean isRemovalAllowed() {
		for ( final String knower : whoKnowsAboutIt ) {
			if (!whoKnowsWhatVersion.get(knower).equals(highestVersion)) 
				return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "ID = " + id + "\nHighest Version Known = "+highestVersion + "\nKnowers : " +whoKnowsWhatVersion+ "\n";
	}
}
